<!-- 右侧弹框组件 -->
<template>
  <div v-show="closed" class="right-sidebar-wrapper clearfix" @click.self="toggle(false)">
    <transition name="fade" enter-active-class="slideInRight" leave-active-class="slideOutRight" @after-leave="closed = false">
      <div v-show="visible" :style="{width: typeof width === 'number' ? (width + 'px') : width}" class="right-sidebar-container">
        <p class="right-sidebar-header">
          <span class="title">{{ title }}</span>
          <el-button icon="el-icon-close" type="text" @click.native="toggle(false)"></el-button>
        </p>
        <el-scrollbar wrap-class="scrollbar-wrapper" style="height: 96%; ">
          <slot></slot>
        </el-scrollbar>
      </div>
    </transition>
  </div>
</template>

<script>
export default {
  name: 'RightSidebar',
  model: {
    prop: 'value',
    event: 'toggle'
  },
  props: {
    value: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: '标题'
    },
    width: {
      type: [String, Number],
      default: 350
    }
  },
  data() {
    return {
      visible: this.value,
      closed: this.value
    }
  },
  watch: {
    value(val) {
      if (val) {
        this.closed = val
      }
      this.visible = val
    }
  },
  methods: {
    toggle(val) {
      this.visible = val
      this.$emit('toggle', val)
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/variables.scss";
.right-sidebar-wrapper{
  position: fixed;
  z-index: 99;
  top: 0;
  left: 0;
  bottom: 0;
  right: 0;
}
.right-sidebar-container{
  float: right;
  height: 100%;
  min-width: 445px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 0 15px 8px darken($color-border-1, 10%);
  box-sizing: border-box;
  padding: 15px;
  position: relative;
  background: #F5F7FA;
}
.right-sidebar-header{
  font-size: $font-size-large;
  // line-height: 24px;
  color: #303133;
  margin: 0;
  padding-bottom: 8px;
  border-bottom: 1px solid $color-border-2;
  .el-button {
    float: right;
    cursor: pointer;
    font-size: $font-size-large;
    position: absolute;
    top: 15px;
    right: 23px;
    padding: 0;
  }
}
</style>
